package com.hope.hotel.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.hope.hotel.common.Result;
import com.hope.hotel.mapper.BookingMapper;
import com.hope.hotel.service.BookingService;
import com.hope.hotel.service.PaymentService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 支付控制器
 */
@RestController
@RequestMapping("/payment")
@RequiredArgsConstructor
public class PaymentController {

    private final PaymentService paymentService;

    private final BookingService bookingService;

    /**
     * 创建支付订单
     */
    @GetMapping("/create/{bookingId}")
    public void createPayment(@PathVariable String bookingId, HttpServletResponse response) throws AlipayApiException, IOException {
        // 从请求中获取用户ID
//        String userId = (String) request.getAttribute("userId");
         paymentService.createPayment(bookingId ,response);
    }

    /**
     * 支付成功异步通知
     */
    @PostMapping("/notify")
    public void notifyPayment(HttpServletRequest request) {
        System.out.println("进入回调notify");
       paymentService.notifyPayment(request);
    }

} 